package com.qst.system.controller;

import com.qst.common.core.controller.BaseController;
import com.qst.common.core.domain.AjaxResult;
import com.qst.common.core.page.TableDataInfo;
import com.qst.system.domain.vo.IdcardVo;
import com.qst.system.service.IIdcardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/system/idcard")
public class IdcardController extends BaseController {

    @Autowired
    private IIdcardService idcardService;
    /**
     * 查询身份证识别列表
     */
    @PreAuthorize("@ss.hasPermi('system:idcard:list')")
    @GetMapping("/list")
    public TableDataInfo list(IdcardVo idcard) {
        startPage();
        List<IdcardVo> list = idcardService.selectIdcardList(idcard);
        return getDataTable(list);
    }
    /**
     * 获取身份证识别详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:idcard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(idcardService.selectIdcardById(id));
    }
    /**
     * 新增身份证识别
     */
    @PreAuthorize("@ss.hasPermi('system:idcard:add')")
    @PostMapping
    public AjaxResult add(@RequestBody IdcardVo idcard) {
        int result = idcardService.insertIdcard(idcard);
        if (result > 0) {
            return AjaxResult.success("新增成功");
        } else {
            return AjaxResult.error("新增失败");
        }
    }
    /**
     * 修改身份证识别
     */
    @PreAuthorize("@ss.hasPermi('system:idcard:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody IdcardVo idcard) {
        int result = idcardService.updateIdcard(idcard);
        if (result > 0) {
            return AjaxResult.success("修改成功");
        } else {
            return AjaxResult.error("修改失败");
        }
    }
    /**
     * 删除身份证识别
     */
    @PreAuthorize("@ss.hasPermi('system:idcard:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        if (ids.length == 1) {
            return toAjax(idcardService.deleteIdcardById(ids[0]));
        }
        return toAjax(idcardService.deleteIdcardByIds(ids));
    }


    @GetMapping("/getCompanyName")
    public AjaxResult getCompanyName() {
        // 这里调用Service层方法获取企业名称列表
        // 假设Service层有对应的方法
        return AjaxResult.success(idcardService.getCompanyName());
    }
}
